﻿Public Class ObservableImpl
    Implements Observable

    Private observerList As List(Of Observer) = New List(Of Observer)

    Public Sub Register(ByVal anObserver As Observer) Implements Observable.Register
        Dim synchList = ArrayList.Synchronized(observerList)
        synchList.Add(anObserver)
    End Sub

    Public Sub UnRegister(ByVal anObserver As Observer) Implements Observable.UnRegister
        Dim synchList = ArrayList.Synchronized(observerList)
        synchList.Remove(anObserver)
    End Sub

    Public Sub NotifyObservers()
        Dim threadSaveCopyOfList As List(Of Observer)
        Dim synchList = ArrayList.Synchronized(observerList)
        SyncLock synchList
            threadSaveCopyOfList = New List(Of Observer)(observerList)
        End SyncLock
        For Each anObserver In threadSaveCopyOfList
            anObserver.Notify()
        Next
    End Sub

End Class
